<?php

namespace App\HttpController;

use App\Service\NoticeService;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroup;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccess;
use EasySwoole\HttpAnnotation\AnnotationTag\Method;
use EasySwoole\HttpAnnotation\AnnotationTag\Param;
use EasySwoole\ORM\Exception\Exception;
use Throwable;

/**
 * @ApiGroup(groupName="通知公告")
 */
class Notice extends BaseController
{
    /**
     * @Api(name="获取页面公告", path="/notice/getNotice", version="1.0.0")
     * @ApiDescription(value="获取页面公告")
     * @Method(allow={POST})
     * @Param(name="type", description="类型：0.首页，1.商城", defaultValue="0", from={JSON})
     * @ApiSuccess({"code": 200,"result": ["紧急通知：紧急通知紧急通知紧急通知紧急通知紧急通知"],"msg": "获取成功"})
     * @return bool
     * @throws Exception
     * @throws Throwable
     */
    public function getNotice($type): bool
    {
        $res = NoticeService::getInstance()->getNotice($type);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }

    /**
     * @Api(name="获取公告列表", path="/notice/getNoticeList", version="1.0.0")
     * @ApiDescription(value="获取公告列表")
     * @Method(allow={POST})
     * @Param(name="type", description="类型：0.首页，1.商城，2.员工端公告信息", defaultValue="0", from={JSON})
     * @Param(name="limit", defaultValue=10, description="单页数量", from={JSON})
     * @Param(name="page", defaultValue=1, description="页数", from={JSON})
     * @ApiSuccess({"code": 200,"result": ["紧急通知：紧急通知紧急通知紧急通知紧急通知紧急通知"],"msg": "获取成功"})
     * @return bool
     * @throws Exception
     * @throws Throwable
     */
    public function getNoticeList($type, $limit, $page): bool
    {
        $res = NoticeService::getInstance()->getNoticeList($type, $limit, $page);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }

    /**
     * @Api(name="获取公告详情", path="/notice/getNoticeDetail", version="1.0.0")
     * @ApiDescription(value="获取公告详情")
     * @Method(allow={POST})
     * @Param(name="id", description="公告id", defaultValue="0", from={JSON})
     * @return bool
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getNoticeDetail($id): bool
    {
        $res = NoticeService::getInstance()->getNoticeDetail($id);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }

    /**
     * @Api(name="交房信息", path="/notice/getDelivery", version="1.0.0")
     * @ApiDescription(value="交房信息")
     * @Method(allow={POST})
     * @return bool
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getDelivery(): bool
    {
        $res = NoticeService::getInstance()->getDelivery($this->uid);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }

    /**
     * @Api(name="获取交房通知", path="/notice/getDeliveryNotice", version="1.0.0")
     * @ApiDescription(value="获取交房通知")
     * @Method(allow={POST})
     * @return bool
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\Mysqli\Exception\Exception
     */
    public function getDeliveryNotice(): bool
    {
        $res = NoticeService::getInstance()->getDeliveryNotice();
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }
}